<template>
  <div class="from">
    <el-form
      :model="ruleForm"
      status-icon
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="姓名" prop="name">
        <el-input
          class="ipt"
          type="text"
          v-model="ruleForm.name"
          autocomplete="off"
        ></el-input>
      </el-form-item>
      <!-- <el-form-item label="确认密码" prop="checkPass">
      <el-input
        type="password"
        v-model="ruleForm.checkPass"
        autocomplete="off"
      ></el-input>
    </el-form-item> -->
      <el-form-item label="身份证号" prop="card">
        <el-input v-model.number="ruleForm.card" class="ipt"></el-input>
      </el-form-item>
      <el-form-item label="手机号" prop="phone">
        <el-input
          class="ipt"
          type="text"
          v-model="ruleForm.phone"
          autocomplete="off"
        ></el-input>
      </el-form-item>
      <el-form-item class="btn">
        <el-button type="primary" @click="submitForm('ruleForm')"
          >立即查询</el-button
        >
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
      <div class="wran">
        <span>注:</span>
        <p>1.查询结果不得用于第三方</p>
        <p>2.征信查询后该客户进入未放款客户列表中</p>
      </div>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    var checkCard = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("身份证号码不能为空"));
      }
      setTimeout(() => {
        if (!Number.isInteger(value)) {
          callback(new Error("请输入数字值"));
        } else {
          if (value < 18) {
            callback(new Error("必须年满18岁"));
          } else {
            callback();
          }
        }
      }, 1000);
    };
    var validateName = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入姓名"));
      } else {
        if (this.ruleForm.checkName !== "") {
          this.$refs.ruleForm.validateField("checkName");
        }
        callback();
      }
    };
    var validatePhone = (rule, value, callback) => {
      const reg = /^[1][3,4,5,7,8][0-9]{9}$/;
      if (value == "" || value == undefined || value == null) {
        callback();
      } else {
        if (!reg.test(value) && value != "") {
          callback(new Error("请输入正确的电话号码"));
        } else {
          callback();
        }
      }
    };
    // var validatePass2 = (rule, value, callback) => {
    //   if (value === "") {
    //     callback(new Error("请再次输入密码"));
    //   } else if (value !== this.ruleForm.pass) {
    //     callback(new Error("两次输入密码不一致!"));
    //   } else {
    //     callback();
    //   }
    // };
    return {
      ruleForm: {
        name: "",
        phone: "",
        card: "",
      },
      rules: {
        name: [{ validator: validateName, trigger: "blur" }],
        // checkPass: [{ validator: validatePass2, trigger: "blur" }],
        card: [{ validator: checkCard, trigger: "blur" }],
        phone:[{ validator: validatePhone, trigger: "blur"  }]
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          confirm("成功查询将扣除X积分是继续查询？");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<style>
.ipt {
  width: 200px;
  height: 30px;
  text-align: center;
}
.from {
  width: 400px;
  height: 250px;
  background: rgba(123, 203, 240, 0.2);
  position: absolute;
  top: 100px;
  left: 500px;
  border-radius: 10px;
}
.wran {
  /* background: skyblue; */
  width: 300px;
  height: 60px;
  position: absolute;
  left: 95px;
  font-size: 13px;
}
.wran p {
  line-height: 2px;
  font-size: 13px;
  font-family: 宋体;
}
.wran span {
  font-family: 宋体;
}
</style>